<template>
<van-popup round position="bottom" v-model:show="show" >
<div class="pop">
  <div class="header">
    请选择类型
    <van-icon @click="close" name="cross"  class="corss"/>
  </div>
  <div class="content">
    <div class="all"  :class="{'active':state.active==='all'}">全部类型</div>
    <div class="title">支出</div>
    <div class="expense-wrap">
      <p @click="chooseType(item)" :class="{'active':state.active===item.ids}"  v-for="item in state.expense" :key="item.id">{{ item.name }}</p>

    </div>

    <div class="title">收入</div>
    <div class="income-wrap">
      <p @click="chooseType(item)" :class="{'active':state.active===item.ids}"  v-for="item in state.income" :key="item.id">{{ item.name }}</p>


    </div>
  </div>
</div>
</van-popup>
</template>

<script setup>
import { ref } from 'vue';
import axios from '../api/axios.js'
import { onMounted } from 'vue';
import { reactive } from 'vue';
const show=ref(false)

const emites=defineEmits(['select'])

const state=reactive({
  expense:[],
  income:[],
  active:'all',

})



onMounted(async()=>{
  const res= await axios.get('/type/list')
  console.log(res);s
  state.expense=res.data.list.filter((item)=>{return  item.type==='1'})
  state.income=res.data.list.filter((item)=>{return  item.type==='2'})

})

const chooseType=(item)=>{
  console.log(item);
  state.active=item.id
  show.value=false
  emites('select',item)
}

defineExpose({
  show
})
</script>



<style lang='less' scoped>
@import '../assets/style/custom.less';
  .item {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.1);
    margin-bottom: 10px;
    .header-date {
      height: 60px;
      display: flex;
      background-color: #f9f9f9;
      align-items: center;
      justify-content: space-between;
      padding: 0 10px;
      div {
        color: @color-text-base;
      }
      .money {
        span {
          margin-left: 20px;
          b {
            color: @color-text-caption;
            font-weight: normal;
            background-color: #f5f5f5;
            padding: 3px;
            margin-right: 2px;
          }
        }
      }
    }
  }
</style>
<style lang='less' scoped>
@import '../assets/style/custom.less';
.pop {
    position: relative;
    background-color: #f5f5f5;
    .header {
      position: sticky;
      top: 0;
      left: 0;
      z-index: 1000;
      width: 100%;
      height: 56px;
      text-align: center;
      font-size: 14px;
      line-height: 56px;
      color: @color-text-base;
      background-color: #fff;
      .cross {
        position: absolute;
        left: 10px;
        top: 50%;
        font-size: 20px;
        transform: translateY(-50%);
        color: @color-text-secondary;
      }
    }
    .content {
      padding: 20px;
      .all {
        display: inline-block;
        padding: 12px 20px;
        font-size: 16px;
        color: @color-text-base;
        background-color: #fff;
      }
      .title {
        color: @color-text-caption;
        margin: 10px 0;
        font-size: 14px;
      }
      .expense-wrap, .income-wrap {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        p {
          width: calc(~"(100% - 20px) / 3");
          text-align: center;
          padding: 12px 0;
          margin-bottom: 10px;
          background-color: #fff;
          font-size: 16px;
        }
      }
      .active {
        background-color: @primary!important;
        color: #fff;
      }
    }
  }
</style>